<template>
  <el-dialog
    draggable
    overflow
    v-model="visible"
    :title="'编辑'"
    :width="600"
    @keyup.enter="$emit('closed')"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <sc-water-mark ref="wm" text="已审核" :color="'rgba(128,128,128,0.1)'">
      <sk-tabs type="border-card">
        <el-tab-pane ref="tab" label="基础信息">
          <el-form
            :model="form"
            ref="dialogForm"
            label-width="70px"
            label-position="right"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="品名" prop="material.name">
                  <el-input v-model="form.material.name" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="客户品名" prop="custno">
                  <el-input v-model="form.custno" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="缸号" prop="dyelot">
                  <el-input v-model="form.dyelot" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="颜色" prop="color_name">
                  <el-input v-model="form.color_name" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="库位" prop="location.name">
                  <el-input v-model="form.location.name" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="流转号" prop="batchno">
                  <el-input v-model="form.batchno" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="匹" prop="auxiliary_quantity">
                  <el-input v-model="form.auxiliary_quantity" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="数" prop="quantity">
                  <el-input v-model="form.quantity" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>

          <sc-VxeTable
            ref="save"
            :gridEvts="gridEvts"
            :data="form.packs"
            :gridOps="gridOps"
            :height="600"
            :tablecode="'market_delivery_pack'"
          >
          </sc-VxeTable>
        </el-tab-pane>
      </sk-tabs>
    </sc-water-mark>
  </el-dialog>
</template>

<script>
export default {
  emits: ["success", "closed"],
  components: {},
  data() {
    return {
      mode: "add",
      gridEvts: {},

      form: {
        location: {},
        material: {},
        packs: [],
      },

      visible: false,
      gridOps: {
        height: 300,
        columns: [
          {
            field: "quantity",
            event: {
              keyup: ({ row, params }) => {
                row["se_quantity"] = row["quantity"];
                this.form.se_quantity = this.form.packs.reduce(
                  (sum, v) => sum + parseFloat(v.quantity),
                  0
                );
                params.$grid.updateFooter();
              },
            },
          },
        ],
      },
    };
  },
  mounted() {},

  methods: {
    //显示
    open() {
      this.visible = true;
      this.$nextTick(() => {
        if (this.form.status_id == 1) {
          this.$refs.wm.create();
        } else {
          this.$refs.wm.clear();
        }
      });
      return this;
    },

    //表单注入数据
    setData(data) {
      this.form = data;
    },
  },
};
</script>
